import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { mergeMap, tap, catchError } from 'rxjs/operators';
import { Injectable } from '@angular/core';
// import { catchError } from 'rxjs/operators';
@Injectable()
export class CusHttpInterceptor implements HttpInterceptor {
  constructor () {}
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    // return next.handle(req).pipe(tap(() => console.log('interceptor')))
    return next.handle(req).pipe(tap((event) => {
      // console.log('type', typeof(event))
      if (event instanceof HttpResponse) {
        if (event.status === 200) {
          console.log('body', event.body);
        } else {
          console.log('请求错误，错误码', event.status)
        }
      }
    }, error => {
      console.log('http fail code', error.status);
      console.log('http err msg', error.message);
    }));
  }
}  